package com.dmx.fw.bean.mapping.pojo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.CollectionOfElements;


/**
 * Operator generated by MyEclipse - Hibernate Tools
 */

@Entity
@Table(name="SYSTEM_OPTR")
public class Operator implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8212907083352503593L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO,generator="optr_seq_gen")
	@SequenceGenerator(name = "optr_seq_gen", sequenceName = "SEQ_OPTR")
	@Column(name = "ID", precision = 12, scale = 0)
	private Long id;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "LAST_UPDATED_TIME")
	private Date lastUpdatedTime;
	
	@Column(name="ORG_ID",precision = 12, scale = 0)
	private Long organizationId;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ORG_ID",insertable=false,updatable=false)
	private Organization organization;
	
	@Column(name="LOGIN",length=20)
	private String login;
	
	@Column(name="PWD",length=64)
	private String password;
	
	@Column(name="NAME",length=60)
	private String name;
	
	@Column(name="OFFICE_PHONE",length=20)
	private String officePhone;
	
	@Column(name="STATUS")
	private String status;
	
	@Column(name="OPRT_TYPE",length=8)
	private String operatorType;
	
	@Column(name="POSITION_CODE")
	private String position;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CREATED_BY",insertable=false,updatable=false)
	private Operator createdOperator;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "CREATED_TIME")
	private Date createdTime;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="LAST_UPDATED_BY")
	private Operator lastUpdatedOperator;
	
	@ManyToMany(fetch=FetchType.LAZY)
	@CollectionOfElements
	@JoinTable(name = "SYSTEM_OPTR_ROLE", joinColumns = @JoinColumn(name = "OPTR_ID"), 
			inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
	private Set<Role> roles = new HashSet<Role>(0);
	
	@OneToMany(targetEntity=Log.class,fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	@CollectionOfElements
	@JoinColumn(name="OPTR_ID")
	private Set<Log> logs = new HashSet<Log>(0);
	
	@Transient
	private List<String> roleIds = new ArrayList<String>(0);

	// Constructors

	/** default constructor */
	public Operator() {
	}

	/** full constructor */
	public Operator(Long organizationId, Organization organization,
			String login, String password, String name, String officePhone,
			String status, String operatorType, String position,
			Operator createdOperator, Date createdTime,
			Operator lastUpdatedOperator, Set roles, Set logs) {
		this.organizationId = organizationId;
		this.organization = organization;
		this.login = login;
		this.password = password;
		this.name = name;
		this.officePhone = officePhone;
		this.status = status;
		this.operatorType = operatorType;
		this.position = position;
		this.createdOperator = createdOperator;
		this.createdTime = createdTime;
		this.lastUpdatedOperator = lastUpdatedOperator;
		this.roles = roles;
		this.logs = logs;
	}

	public List<String> getRoleIds() {
		return roleIds;
	}

	public String getUserId() {
		return id != null ? id.toString() : null;
	}

	// Property accessors

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getLastUpdatedTime() {
		return this.lastUpdatedTime;
	}

	public void setLastUpdatedTime(Date lastUpdatedTime) {
		this.lastUpdatedTime = lastUpdatedTime;
	}

	public Long getOrganizationId() {
		return this.organizationId;
	}

	public void setOrganizationId(Long organizationId) {
		this.organizationId = organizationId;
	}

	public Organization getOrganization() {
		return this.organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOfficePhone() {
		return this.officePhone;
	}

	public void setOfficePhone(String officePhone) {
		this.officePhone = officePhone;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getOperatorType() {
		return this.operatorType;
	}

	public void setOperatorType(String operatorType) {
		this.operatorType = operatorType;
	}

	public String getPosition() {
		return this.position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public Operator getCreatedOperator() {
		return this.createdOperator;
	}

	public void setCreatedOperator(Operator createdOperator) {
		this.createdOperator = createdOperator;
	}

	public Date getCreatedTime() {
		return this.createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Operator getLastUpdatedOperator() {
		return this.lastUpdatedOperator;
	}

	public void setLastUpdatedOperator(Operator lastUpdatedOperator) {
		this.lastUpdatedOperator = lastUpdatedOperator;
	}

	public Set getRoles() {
		return this.roles;
	}

	public void setRoles(Set roles) {
		this.roles = roles;
	}

	public Set getLogs() {
		return this.logs;
	}

	public void setLogs(Set logs) {
		this.logs = logs;
	}

}